/*
 * GoHomeAndSleepTilRested.java
 *
 * Created on March 27, 2007, 11:18 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package ai9hells.pgaibe.chapter2.westworldwithmessaging;

import ai9hells.pgaibe.common.fsm.State;
import ai9hells.pgaibe.common.messaging.Telegram;

/**
 *
 * @author andre.bandarra
 */
public class GoHomeAndSleepTilRested extends State<Miner> {
    public static final State<Miner> INSTANCE = new GoHomeAndSleepTilRested();
    /** Creates a new instance of GoHomeAndSleepTilRested */
    private GoHomeAndSleepTilRested() {
    }

    public void enter(Miner m) {
        if (m.getLocation() != Locations.SHACK){
            System.out.println(EntityNames.getNameOfEntity(m.getId())+": Walkin' home");
            m.setLocation(Locations.SHACK);
            MessageDispatcher.INSTANCE.dispatchMessage(0, m.getId(),
                    EntityNames.ELSA, MessageTypes.MSG_HI_HONEY_IM_HOME, null);
        }
    }

    public void execute(Miner m) {
        if (!m.isFatigued()){
            System.out.println(EntityNames.getNameOfEntity(m.getId())+": What a God darn fantastic nap! Time to find more gold");
            m.getStateMachine().changeState(EnterMineAndDigForNugget.INSTANCE);
        } else {
            System.out.println(EntityNames.getNameOfEntity(m.getId())+": ZZZZZZZZZ!");
            m.decreaseFatigue();
        }
    }

    public void exit(Miner m) {
        System.out.println(EntityNames.getNameOfEntity(m.getId())+": Leaving the house");
    }

    public boolean onMessage(Miner m, Telegram t) {
        switch(t.getMsg()){
            case MessageTypes.MSG_STEW_READY:
                m.getStateMachine().changeState(EatStew.INSTANCE);
                return true;
            default :return false;
        }
    }

    
}
